﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Drawing;
using System.Web.UI.WebControls;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System.Text.RegularExpressions;
using System.Data;
using System.IO;
using System.Security.Cryptography;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Runda.CMS.Bll;

namespace Runda.CMS.Web.Controls
{
    [ToolboxData("<{0}:Repeater runat=server></{0}:Repeater>"), ToolboxBitmap(typeof(Repeater), "Repeater.bmp")]
    public class Repeater : System.Web.UI.WebControls.Repeater, IPostBackEventHandler
    {
        // Fields
        
        private const string SCRIPT_PAGE = "<script language=\"JavaScript\">\r\n//翻页\r\nfunction goPage(obj, action)\r\n{\r\n\tvar iPage;\r\n\twindow.event.returnValue = false;\r\n\tdocument.all(obj + \":txtLocation\").value = \"\";\r\n\tiPage = parseInt(document.all[obj + \"_ToPage\"].value);\r\n\tiPageCount = parseInt(document.all[obj + \"_PageCount\"].innerText);\r\n\r\n\tswitch(action.toLowerCase())\r\n\t{\r\n\t\tcase \"first\":\t\t\t\t\t// 首页\r\n\t\t\tif(iPageCount>0&&iPage>1)\r\n\t\t\t{\r\n\t\t\t\tdocument.all[obj + \"_ToPage\"].value = 1;\r\n\t\t\t\t__doPostBack(obj, \"PageChange\");\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase \"prev\":\t\t\t\t\t// 上页\r\n\t\t\tif(iPage>1)\r\n\t\t\t{\r\n\t\t\t\tdocument.all[obj + \"_ToPage\"].value = iPage - 1;\r\n\t\t\t\t__doPostBack(obj, \"PageChange\");\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase \"next\":\t\t\t\t\t// 下页\r\n\t\t\tif(iPage<iPageCount)\r\n\t\t\t{\r\n\t\t\t\tdocument.all[obj + \"_ToPage\"].value = iPage + 1;\r\n\t\t\t\t__doPostBack(obj, \"PageChange\");\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase \"last\":\t\t\t\t\t// 尾页\r\n\t\t\tif(iPageCount>0&&iPage<iPageCount)\r\n\t\t\t{\r\n\t\t\t\tdocument.all[obj + \"_ToPage\"].value = iPageCount;\r\n\t\t\t\t__doPostBack(obj, \"PageChange\");\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tdefault:\t\t\t\t\t\t// 转到\r\n\t\t\tif(!isNaN(document.all[obj + \"_CurPage\"].value) && iPage!=parseInt(document.all[obj + \"_CurPage\"].value))\r\n\t\t\t\t__doPostBack(obj, \"PageChange\");\r\n\t\t\tbreak;\r\n\t}\r\n}\r\n</script>";

        private const string SCRIPT_SORT = "<script language=\"JavaScript\">\r\n\t//功能：排序\r\n\tfunction repSort(sRepName, sSortField)\r\n\t{\r\n\t\tvar txtSort = document.all(sRepName + \"_txtSort\");\r\n\r\n\t\tif(!txtSort) return;\r\n\r\n\t\tif(txtSort.value.toLowerCase() == (sSortField + \" ASC\").toLowerCase() ||\r\n\t\t\t\ttxtSort.value.toLowerCase() == sSortField.toLowerCase())\r\n\t\t{\r\n\t\t\ttxtSort.value = sSortField + \" DESC\";\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\ttxtSort.value = sSortField;\r\n\t\t}\r\n\t\t__doPostBack(sRepName, \"Sort\");\r\n\t}\r\n</script>";


        // Nested Types
        public enum Align
        {
            left,
            center,
            right
        }

        public Repeater()
        {
            
        }

        protected override void CreateChildControls()
        {
            this.EnsureChildControls();
            base.CreateChildControls();
        }

        private void CrtChildCtrls()
        {
            TextBox child = new TextBox();
            switch (this.BindMode)
            {
                case 0:
                    {
                        Match match = new Regex(@"\s+ORDER BY\s+([\w\s.,()]*)$").Match(this.SQL);
                        if (!match.Success)
                        {
                            child.Text = "";
                            break;
                        }
                        child.Text = match.Groups[1].Value;
                        break;
                    }
                case 1:
                    {
                        DataTable dataTable = (DataTable)this.DataTable;
                        child.Text = dataTable.DefaultView.Sort;
                        break;
                    }
            }
            child.ID = "txtSort";
            child.AutoPostBack = true;
            child.Style.Add("display", "none");
            this.Controls.Add(child);
            TextBox box2 = new TextBox();
            box2.Text = this.Location;
            box2.ID = "txtLocation";
            box2.Style.Add("display", "none");
            box2.TextChanged += new EventHandler(this.LocationChanged);
            this.Controls.Add(box2);
            if (this.EnablePager)
            {
                this.Controls.Add(new LiteralControl("<table class=\"" + this.FooterCssClass + "\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" height=\"22\">"));
                this.Controls.Add(new LiteralControl("<tr><td style=\"padding-left:8px;\">"));
                this.Controls.Add(new LiteralControl("<nobr>页次："));
                if (this.ViewState["CurPage"] == null)
                {
                    this.ViewState["CurPage"] = 1;
                }
                TextBox box5 = new TextBox();
                box5.Text = StringType.FromObject(this.ViewState["CurPage"]);
                box5.ID = "ToPage";
                box5.MaxLength = 4;
                box5.Style.Add("width", "24px");
                box5.CssClass = "pagenum";
                box5.Attributes.Add("min", "1");
                box5.Attributes.Add("max", StringType.FromObject(this.ViewState["PageCount"]));
                box5.Attributes.Add("onvalidchange", "goPage('" + this.UniqueID + "', '');");
                this.Controls.Add(box5);
                TextBox box = new TextBox();
                box.Style.Add("display", "none");
                box.ID = "CurPage";
                box.Text = StringType.FromObject(this.ViewState["CurPage"]);
                this.Controls.Add(box);
                this.Controls.Add(new LiteralControl("/"));
                Label label = new Label();
                label.Text = StringType.FromObject(this.ViewState["PageCount"]);
                label.ID = "PageCount";
                this.Controls.Add(label);
                this.Controls.Add(new LiteralControl("&nbsp;&nbsp;每页"));
                TextBox box3 = new TextBox();
                box3.Text = StringType.FromInteger(this.PageSize);
                box3.ID = "PageSize";
                box3.MaxLength = 3;
                box3.Style.Add("width", "24px");
                box3.CssClass = "pagenum";
                box3.Attributes.Add("min", "0");
                box3.Attributes.Add("max", "999");
                box3.Attributes.Add("onvalidchange", "__doPostBack('" + this.UniqueID + "$PageSize','')");
                box3.TextChanged += new EventHandler(this.PageSizeChanged);
                this.Controls.Add(box3);
                this.Controls.Add(new LiteralControl("条/共"));
                Label label2 = new Label();
                label2.Text = StringType.FromObject(this.ViewState["RowsCount"]);
                label2.ID = "RowsCount";
                this.Controls.Add(label2);
                this.Controls.Add(new LiteralControl("条"));
                this.Controls.Add(new LiteralControl("</nobr></td>"));
                this.Controls.Add(new LiteralControl("<td align=\"right\"><nobr>"));
                HyperLink link = new HyperLink();
                link.Text = this.FirstPageText;
                if (StringType.StrCmp(this.LinkCssClass, "", false) != 0)
                {
                    link.CssClass = this.LinkCssClass;
                }
                link.Attributes.Add("href", "#");
                link.Attributes.Add("onclick", "goPage('" + this.UniqueID + "', 'First');");
                link.Style.Add("cursor", "hand");
                this.Controls.Add(link);
                this.Controls.Add(new LiteralControl("&nbsp;"));
                HyperLink link4 = new HyperLink();
                link4.Text = this.PrevPageText;
                if (StringType.StrCmp(this.LinkCssClass, "", false) != 0)
                {
                    link4.CssClass = this.LinkCssClass;
                }
                link4.Attributes.Add("href", "#");
                link4.Attributes.Add("onclick", "goPage('" + this.UniqueID + "', 'Prev');");
                link4.Style.Add("cursor", "hand");
                this.Controls.Add(link4);
                this.Controls.Add(new LiteralControl("&nbsp;"));
                HyperLink link3 = new HyperLink();
                link3.Text = this.NextPageText;
                if (StringType.StrCmp(this.LinkCssClass, "", false) != 0)
                {
                    link3.CssClass = this.LinkCssClass;
                }
                link3.Attributes.Add("href", "#");
                link3.Attributes.Add("onclick", "goPage('" + this.UniqueID + "', 'Next');");
                link3.Style.Add("cursor", "hand");
                this.Controls.Add(link3);
                this.Controls.Add(new LiteralControl("&nbsp;"));
                HyperLink link2 = new HyperLink();
                link2.Text = this.LastPageText;
                if (StringType.StrCmp(this.LinkCssClass, "", false) != 0)
                {
                    link2.CssClass = this.LinkCssClass;
                }
                link2.Attributes.Add("href", "#");
                link2.Attributes.Add("onclick", "goPage('" + this.UniqueID + "', 'Last');");
                link2.Style.Add("cursor", "hand");
                this.Controls.Add(link2);
                this.Controls.Add(new LiteralControl("&nbsp;"));
                this.Controls.Add(new LiteralControl("</nobr>"));
                this.Controls.Add(new LiteralControl("</td></tr></table>"));
            }
        }

        public override void DataBind()
        {
            string sQL;
            DataView defaultView = null;
            int num;
            int num2;
            int num3;
            int count;
            string str3;
            string pKField;
            string str5;
           
            switch (this.BindMode)
            {
                case 0:
                    {
                        sQL = this.SQL;

                        if ((sQL == null) | (StringType.StrCmp(sQL, "", false) == 0))
                        {
                            return;
                        }

                        if (!this.EnablePager)
                        {
                            this.PageSize = 0;
                            str5 = sQL;
                            goto Label_0469;
                        }
                        str5 = sQL.Substring(sQL.IndexOf("FROM"));
                        if (str5.LastIndexOf(" ORDER BY") >= 0)
                        {
                            str5 = str5.Substring(0, str5.LastIndexOf(" ORDER BY"));
                        }                        
                        DataTable dt = new CommonBll().getDataFromSQL("SELECT COUNT(*) " + str5);
                        count = Convert.ToInt32(dt.Rows[0][0].ToString());
                        this.ViewState["RowsCount"] = count.ToString();
                        if (this.PageSize <= 0)
                        {
                            this.ViewState["PageCount"] = 1;
                            this.ViewState["CurPage"] = 1;
                            str5 = sQL;
                            goto Label_0469;
                        }
                        num3 = ((count - 1) / this.PageSize) + 1;
                        this.ViewState["PageCount"] = num3;
                        num2 = Convert.ToInt32(this.ViewState["CurPage"]);
                        if (num2 > num3)
                        {
                            num2 = num3;
                        }
                        if (num2 < 1)
                        {
                            num2 = 1;
                        }
                        this.ViewState["CurPage"] = num2.ToString();
                        str3 = this.Location.Split(new char[] { ',' })[0].Trim();
                        if (StringType.StrCmp(str3, "", false) != 0)
                        {
                            str5 = Regex.Replace(sQL, @"SELECT\s+([\w|\W]+)\s+FROM", "SELECT " + this.PKField + " FROM");
                            
                            pKField = this.PKField;
                            if (pKField.LastIndexOf(".") >= 0)
                            {
                                pKField = pKField.Split(new char[] { '.' })[1].Trim();
                            }
                            DataTable location = new CommonBll().getDataFromSQL(str5);
                            int num11 = location.Rows.Count - 1;
                            for (num = 0; num <= num11; num++)
                            {
                                if (StringType.StrCmp(location.Rows[num][pKField].ToString(), str3, false) == 0)
                                {
                                    num2 = (num / this.PageSize) + 1;
                                    this.ViewState["CurPage"] = num2.ToString();
                                    break;
                                }
                            }
                        }
                        break;

                        return;
                    }
                case 1:
                    {
                        DataTable dataTable = (DataTable)this.DataTable;
                        if ((this.FindControl("txtSort") != null) && (this.FindControl("txtSort") is TextBox))
                        {
                            dataTable.DefaultView.Sort = ((TextBox)this.FindControl("txtSort")).Text.Trim();
                        }
                        if (!this.EnablePager)
                        {
                            this.PageSize = 0;
                            defaultView = dataTable.DefaultView;
                        }
                        else
                        {
                            count = dataTable.Rows.Count;
                            this.ViewState["RowsCount"] = count.ToString();
                            if (this.PageSize <= 0)
                            {
                                num3 = 1;
                                this.ViewState["PageCount"] = num3;
                                num2 = 1;
                                this.ViewState["CurPage"] = num2.ToString();
                                defaultView = dataTable.DefaultView;
                            }
                            else
                            {
                                num3 = ((count - 1) / this.PageSize) + 1;
                                this.ViewState["PageCount"] = num3;
                                num2 = Convert.ToInt32(this.ViewState["CurPage"]);
                                if (num2 > num3)
                                {
                                    num2 = num3;
                                }
                                if (num2 < 1)
                                {
                                    num2 = 1;
                                }
                                this.ViewState["CurPage"] = num2.ToString();
                                str3 = this.Location.Split(new char[] { ',' })[0].Trim();
                                if (StringType.StrCmp(str3, "", false) != 0)
                                {
                                    pKField = this.PKField;
                                    if (pKField.LastIndexOf(".") >= 0)
                                    {
                                        pKField = pKField.Split(new char[] { '.' })[1].Trim();
                                    }
                                    int num9 = dataTable.DefaultView.Count - 1;
                                    for (num = 0; num <= num9; num++)
                                    {
                                        if (StringType.StrCmp(dataTable.DefaultView[num][pKField].ToString(), str3, false) == 0)
                                        {
                                            num2 = (num / this.PageSize) + 1;
                                            this.ViewState["CurPage"] = num2.ToString();
                                            break;
                                        }
                                    }
                                }
                                DataTable table2 = dataTable.Clone();
                                int num8 = (num2 * this.PageSize) - 1;
                                for (num = (num2 - 1) * this.PageSize; num <= num8; num++)
                                {
                                    if (num >= dataTable.Rows.Count)
                                    {
                                        break;
                                    }
                                    DataRow row = table2.NewRow();
                                    int num7 = table2.Columns.Count - 1;
                                    for (int i = 0; i <= num7; i++)
                                    {
                                        row[i] = dataTable.DefaultView[num][i];
                                    }
                                    table2.Rows.Add(row);
                                }
                                defaultView = table2.DefaultView;
                            }
                        }
                        goto Label_077E;
                    }
                default:
                    goto Label_077E;
            }
            str5 = sQL.Substring(sQL.IndexOf("SELECT ") + 6);
            str5 = "SELECT TOP " + this.PageSize.ToString() + str5;
            if ((num2 > 1) && (StringType.StrCmp(this.PKField.Trim(), "", false) != 0))
            {
                string[] strArray = new string[] { this.PKField.Trim().Replace("'", "''"), " NOT IN (SELECT TOP ", (this.PageSize * (num2 - 1)).ToString(), " ", this.PKField.Trim().Replace("'", "''"), " ", sQL.Substring(sQL.IndexOf("FROM ")), ")" };
                string str6 = string.Concat(strArray);
                if (str5.LastIndexOf("WHERE ") > 0)
                {
                    str5 = str5.Replace("WHERE ", "WHERE " + str6 + " AND ");
                }
                else if (str5.IndexOf("ORDER BY ") > 0)
                {
                    str5 = str5.Replace("ORDER BY ", "WHERE " + str6 + " ORDER BY ");
                }
                else
                {
                    str5 = str5 + " WHERE " + str6;
                }
            }
        Label_0469:            
            defaultView = new CommonBll().getDataFromSQL(str5).DefaultView;
        Label_077E:
            if ((StringType.StrCmp(this.NumberField, "", false) != 0) && (defaultView.Table.Columns.IndexOf(this.NumberField) >= 0))
            {
                int num6 = defaultView.Count - 1;
                for (num = 0; num <= num6; num++)
                {
                    defaultView[num][this.NumberField] = ObjectType.AddObj(num + 1, ObjectType.MulObj(this.PageSize, ObjectType.SubObj(this.ViewState["CurPage"], 1)));
                }
            }
            base.DataSource = defaultView;
            base.DataBind();
        }

        public void GetSortText(string strSortField)
        {
            if ((this.FindControl("txtSort") != null) && (this.FindControl("txtSort") is TextBox))
            {
                TextBox box = (TextBox)this.FindControl("txtSort");
                if (StringType.StrCmp(strSortField.ToLower(), box.Text.ToLower(), false) == 0)
                {
                    this.Page.Response.Output.Write(this.SortSignASC);
                }
                else if (StringType.StrCmp((strSortField + " desc").ToLower(), box.Text.ToLower(), false) == 0)
                {
                    this.Page.Response.Output.Write(this.SortSignDESC);
                }
            }
        }

        private void LocationChanged(object sender, EventArgs e)
        {
            TextBox box = (TextBox)sender;
            this.Location = box.Text;
        }

        protected override void OnInit(EventArgs e)
        {
            this.EnableViewState = true;

            base.OnInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            this.CrtChildCtrls();
            base.OnLoad(e);
        }

        protected override void OnPreRender(EventArgs e)
        {
            if (this.EnablePager & !this.Page.IsClientScriptBlockRegistered("PageScript"))
            {
                this.Page.RegisterClientScriptBlock("PageScript", "<script language=\"JavaScript\">\r\n//翻页\r\nfunction goPage(obj, action)\r\n{\r\n\tvar iPage;\r\n\twindow.event.returnValue = false;\r\n\tdocument.all(obj + \":txtLocation\").value = \"\";\r\n\tiPage = parseInt(document.all[obj + \"_ToPage\"].value);\r\n\tiPageCount = parseInt(document.all[obj + \"_PageCount\"].innerText);\r\n\r\n\tswitch(action.toLowerCase())\r\n\t{\r\n\t\tcase \"first\":\t\t\t\t\t// 首页\r\n\t\t\tif(iPageCount>0&&iPage>1)\r\n\t\t\t{\r\n\t\t\t\tdocument.all[obj + \"_ToPage\"].value = 1;\r\n\t\t\t\t__doPostBack(obj, \"PageChange\");\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase \"prev\":\t\t\t\t\t// 上页\r\n\t\t\tif(iPage>1)\r\n\t\t\t{\r\n\t\t\t\tdocument.all[obj + \"_ToPage\"].value = iPage - 1;\r\n\t\t\t\t__doPostBack(obj, \"PageChange\");\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase \"next\":\t\t\t\t\t// 下页\r\n\t\t\tif(iPage<iPageCount)\r\n\t\t\t{\r\n\t\t\t\tdocument.all[obj + \"_ToPage\"].value = iPage + 1;\r\n\t\t\t\t__doPostBack(obj, \"PageChange\");\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase \"last\":\t\t\t\t\t// 尾页\r\n\t\t\tif(iPageCount>0&&iPage<iPageCount)\r\n\t\t\t{\r\n\t\t\t\tdocument.all[obj + \"_ToPage\"].value = iPageCount;\r\n\t\t\t\t__doPostBack(obj, \"PageChange\");\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tdefault:\t\t\t\t\t\t// 转到\r\n\t\t\tif(!isNaN(document.all[obj + \"_CurPage\"].value) && iPage!=parseInt(document.all[obj + \"_CurPage\"].value))\r\n\t\t\t\t__doPostBack(obj, \"PageChange\");\r\n\t\t\tbreak;\r\n\t}\r\n}\r\n</script>");
            }
            if (!this.Page.IsClientScriptBlockRegistered("ScriptSort"))
            {
                this.Page.RegisterClientScriptBlock("ScriptSort", "<script language=\"JavaScript\">\r\n\t//功能：排序\r\n\tfunction repSort(sRepName, sSortField)\r\n\t{\r\n\t\tvar txtSort = document.all(sRepName + \"_txtSort\");\r\n\r\n\t\tif(!txtSort) return;\r\n\r\n\t\tif(txtSort.value.toLowerCase() == (sSortField + \" ASC\").toLowerCase() ||\r\n\t\t\t\ttxtSort.value.toLowerCase() == sSortField.toLowerCase())\r\n\t\t{\r\n\t\t\ttxtSort.value = sSortField + \" DESC\";\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\ttxtSort.value = sSortField;\r\n\t\t}\r\n\t\t__doPostBack(sRepName, \"Sort\");\r\n\t}\r\n</script>");
            }
            base.OnPreRender(e);
        }

        private void PageSizeChanged(object sender, EventArgs e)
        {
            int num = 0;
            TextBox box = (TextBox)sender;
            if (Information.IsNumeric(box.Text))
            {
                string str;
                num = IntegerType.FromString(box.Text);
                if (num < 0)
                {
                    num = 0;
                }
            }
            box.Text = StringType.FromInteger(num);
            if (this.PageSize != num)
            {
                this.PageSize = num;
                this.DataBind();
                this.CrtChildCtrls();
            }
        }

        public void RaisePostBackEvent(string eventArgument)
        {
            string str3 = eventArgument;
            if (StringType.StrCmp(str3, "PageChange", false) == 0)
            {
                if ((this.FindControl("ToPage") != null) && (this.FindControl("ToPage") is TextBox))
                {
                    this.ViewState["CurPage"] = ((TextBox)this.FindControl("ToPage")).Text;
                }
                this.DataBind();
                this.CrtChildCtrls();
            }
            else if ((StringType.StrCmp(str3, "Sort", false) == 0) && ((this.FindControl("txtSort") != null) && (this.FindControl("txtSort") is TextBox)))
            {
                string str = ((TextBox)this.FindControl("txtSort")).Text.Trim();
                switch (this.BindMode)
                {
                    case 0:
                        {
                            Regex regex = new Regex(@"\s+ORDER BY\s+([\w\s.,()]*)$");
                            string sQL = this.SQL;
                            if (StringType.StrCmp(str, "", false) != 0)
                            {
                                if (!regex.IsMatch(sQL))
                                {
                                    sQL = sQL + " ORDER BY " + str;
                                }
                                else
                                {
                                    sQL = regex.Replace(sQL, " ORDER BY " + str);
                                }
                                this.SQL = sQL;
                                this.DataBind();
                                this.CrtChildCtrls();
                            }
                            return;
                        }
                    case 1:
                        {
                            DataTable dataTable = (DataTable)this.DataTable;
                            dataTable.DefaultView.Sort = str;
                            this.DataBind();
                            this.CrtChildCtrls();
                            return;
                        }
                }
            }
        }

        //Properties
        [Description("绑定模式。"), Category("Data"), Browsable(false), DefaultValue(0)]
        public int BindMode
        {
            get
            {
                if (this.ViewState["BindMode"] == null)
                {
                    return 0;
                }
                return Convert.ToInt32(this.ViewState["BindMode"]);
            }
            set
            {
                this.ViewState["BindMode"] = value;
            }
        }



        [Browsable(false)]
        public override string DataMember
        {
            get
            {
                return base.DataMember;
            }
            set
            {
                base.DataMember = value;
            }
        }

        [Browsable(false)]
        public override object DataSource
        {
            get
            {
                return base.DataSource;
            }
            set
            {
                base.DataSource = RuntimeHelpers.GetObjectValue(value);
            }
        }

        [Browsable(false)]
        public object DataTable
        {
            get
            {
                return this.ViewState["DataTable"];
            }
            set
            {
                this.ViewState["DataTable"] = RuntimeHelpers.GetObjectValue(value);
            }
        }

        [DefaultValue(true), Description("是否允许翻页工具条。"), Category("Appearance")]
        public bool EnablePager
        {
            get
            {
                return ((this.ViewState["EnablePager"] == null) || Convert.ToBoolean(RuntimeHelpers.GetObjectValue(this.ViewState["EnablePager"])));
            }
            set
            {
                this.ViewState["EnablePager"] = value;
            }
        }

        [Description("首页链接文字。"), DefaultValue("[首页]"), Category("Appearance")]
        public string FirstPageText
        {
            get
            {
                if (this.ViewState["FirstPageText"] == null)
                {
                    return "[首页]";
                }
                return StringType.FromObject(this.ViewState["FirstPageText"]);
            }
            set
            {
                this.ViewState["FirstPageText"] = value;
            }
        }

        [Category("Appearance"), Description("翻页行样式。"), DefaultValue("gridBar")]
        public string FooterCssClass
        {
            get
            {
                if (this.ViewState["FooterCSS"] == null)
                {
                    return "gridBar";
                }
                return StringType.FromObject(this.ViewState["FooterCSS"]);
            }
            set
            {
                this.ViewState["FooterCSS"] = value;
            }
        }

        [DefaultValue("[末页]"), Category("Appearance"), Description("末页链接文字。")]
        public string LastPageText
        {
            get
            {
                if (this.ViewState["LastPageText"] == null)
                {
                    return "[末页]";
                }
                return StringType.FromObject(this.ViewState["LastPageText"]);
            }
            set
            {
                this.ViewState["LastPageText"] = value;
            }
        }

        [Description("翻页链接对齐方式。"), DefaultValue(2), Category("Appearance")]
        public Align LinkAlign
        {
            get
            {
                if (this.ViewState["LinkAlign"] == null)
                {
                    return Align.left;
                }
                return (Align)int.Parse(StringType.FromObject(this.ViewState["LinkAlign"]));
            }
            set
            {
                this.ViewState["LinkAlign"] = value;
            }
        }

        [Category("Appearance"), Description("翻页链接样式。"), DefaultValue("pager")]
        public string LinkCssClass
        {
            get
            {
                if (this.ViewState["LinkCSS"] == null)
                {
                    return "pager";
                }
                return StringType.FromObject(this.ViewState["LinkCSS"]);
            }
            set
            {
                this.ViewState["LinkCSS"] = value;
            }
        }

        [Description("前端记录行定位。"), DefaultValue(""), Category("Data")]
        public string Location
        {
            get
            {
                if (this.ViewState["Location"] == null)
                {
                    return "";
                }
                return Convert.ToString(RuntimeHelpers.GetObjectValue(this.ViewState["Location"]));
            }
            set
            {
                this.ViewState["Location"] = value;
            }
        }

        [Category("Appearance"), DefaultValue("[下页]"), Description("下一页链接文字。")]
        public string NextPageText
        {
            get
            {
                if (this.ViewState["NextPageText"] == null)
                {
                    return "[下页]";
                }
                return StringType.FromObject(this.ViewState["NextPageText"]);
            }
            set
            {
                this.ViewState["NextPageText"] = value;
            }
        }

        [Description("序号字段名。"), Category("Data"), DefaultValue("rowid")]
        public string NumberField
        {
            get
            {
                if (this.ViewState["NumField"] == null)
                {
                    return "rowid";
                }
                return StringType.FromObject(this.ViewState["NumField"]);
            }
            set
            {
                this.ViewState["NumField"] = value;
            }
        }

        [Description("每页记录行数。"), Category("Data"), DefaultValue(10)]
        public int PageSize
        {
            get
            {
                if (this.ViewState["PageSize"] == null)
                {
                    return 10;
                }
                return Convert.ToInt32(RuntimeHelpers.GetObjectValue(this.ViewState["PageSize"]));
            }
            set
            {
                this.ViewState["PageSize"] = value;
            }
        }

        [Description("主键名。"), Category("Data"), DefaultValue("id")]
        public string PKField
        {
            get
            {
                if (this.ViewState["PKField"] == null)
                {
                    return "id";
                }
                return StringType.FromObject(this.ViewState["PKField"]);
            }
            set
            {
                this.ViewState["PKField"] = value;
            }
        }

        [Category("Appearance"), DefaultValue("[上页]"), Description("上一页链接文字。")]
        public string PrevPageText
        {
            get
            {
                if (this.ViewState["PrevPageText"] == null)
                {
                    return "[上页]";
                }
                return StringType.FromObject(this.ViewState["PrevPageText"]);
            }
            set
            {
                this.ViewState["PrevPageText"] = value;
            }
        }

        [Category("Appearance"), Description("升序排序标识。"), DefaultValue("^")]
        public string SortSignASC
        {
            get
            {
                if (this.ViewState["SortASC"] == null)
                {
                    return "^";
                }
                return StringType.FromObject(this.ViewState["SortASC"]);
            }
            set
            {
                this.ViewState["SortASC"] = value;
            }
        }

        [Description("降序排序标识。"), Category("Appearance"), DefaultValue("ˇ")]
        public string SortSignDESC
        {
            get
            {
                if (this.ViewState["SortDESC"] == null)
                {
                    return "ˇ";
                }
                return StringType.FromObject(this.ViewState["SortDESC"]);
            }
            set
            {
                this.ViewState["SortDESC"] = value;
            }
        }

        [Category("Data"), Description("数据查询SQL语句。"), Browsable(false)]
        public string SQL
        {
            get
            {
                if (this.ViewState["SQL"] == null)
                {
                    return "";
                }
                return StringType.FromObject(this.ViewState["SQL"]);
            }
            set
            {
                this.ViewState["SQL"] = value;
            }
        }
    }
}
